package org.misty.practices.inject;

import org.misty.practices.inject.core.AppContext;
import org.misty.practices.inject.core.Autowired;

public class LazyLoad implements IWork {
    @Autowired
    private IService service;

    @Override
    public void work() {
        this.service.sayHello();
    }

    public static void main(String[] args) {
        var context = new AppContext();
        context.register(LazyLoad.class);
        context.register(ServiceImpl.class);
        context.register(AnotherServiceImpl.class);

        LazyLoad lazyLoad = context.getBean(LazyLoad.class);
        System.out.println(lazyLoad.service);
        lazyLoad.work();
        System.out.println(lazyLoad.service);
    }
}
